﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WcfMail.Interface;

namespace Hisuntech.SystemFramework.Net.Mail
{
    /// <summary>
    /// 邮件服务器信息
    /// </summary>
    public class MailServerInfo
    {
        /// <summary>
        /// 邮件服务器类型
        /// </summary>
        public MailServerType ServerType { get; set; }
        string _mailServer = string.Empty;
        /// <summary>
        /// 邮件服务器地址
        /// </summary>
        public string MailServer
        {
            get
            {
                return _mailServer;
            }
            set
            {
                _mailServer = value;
            }
        }
        /// <summary>
        /// 使用此邮件服务器的用户名称
        /// </summary>
        string _serverUsername = string.Empty;
        public string ServerUsername
        {
            get
            {
                return _serverUsername;
            }
            set
            {
                _serverUsername = value;
            }
        }
        /// <summary>
        /// 用户密码
        /// </summary>
        string _serverPassword = string.Empty;
        public string ServerPassword
        {
            get
            {
                return _serverPassword;
            }
            set
            {
                _serverPassword = value;
            }
        }
        /// <summary>
        /// 邮件服务器的端口号，如果未设置将根据邮件服务器类型自动设置。
        /// </summary>
        int _mailport = 0;
        public int MailPort
        {
            get
            {
                if (_mailport == 0)
                {
                    if (this.ServerType == MailServerType.SMTP)
                        _mailport = 25;
                    else if (this.ServerType == MailServerType.SMTP)
                        _mailport = 110;
                }
                return _mailport;
            }
            set
            {
                _mailport = value;
            }
        }
        /// <summary>
        /// 缺省的邮件收件人地址
        /// </summary>
        public string MailTo { get; set; }
    }
    /// <summary>
    /// 邮件信息
    /// </summary>
    public class MailMessageInfo : ISysMsg
    {
        public int MessageID { get; set; }
        /// <summary>
        /// 邮件的时间
        /// </summary>
        public DateTime Time { get; set; }

        string _mailFrom = string.Empty;
        public string MailFrom
        {
            get
            {
                return _mailFrom;
            }
            set
            {
                if (value.StartsWith("<") && value.EndsWith(">"))
                {
                    _mailFrom = value.Substring(1, value.Length - 2);
                }
                else
                {
                    _mailFrom = value;
                }
            }
        }

        string _mailTo = string.Empty;
        public string MailTo
        {
            get
            {
                return _mailTo;
            }
            set
            {
                _mailTo = value;
            }
        }

        string _mailCharset = "gb2312";
        public string MailCharset
        {
            get
            {
                return _mailCharset;
            }
            set
            {
                _mailCharset = value;
            }
        }

        byte _iPriority = 3;
        public byte IPriority
        {
            get
            {
                return _iPriority;
            }
            set
            {
                _iPriority = value;
            }
        }

       
        /// <summary>
        /// 添加附件文件名，如果是Notes邮件必须使用绝对路径
        /// </summary>
        /// <param name="fileName"></param>
        public void AddAttachment(string fileName)
        {
            if (_AttachmentFiles == null)
                _AttachmentFiles = new List<string>();
            _AttachmentFiles.Add(fileName);
        }


        private  List<string> _AttachmentFiles=null;
        /// <summary>
        /// 附件文件列表，如果没有任何附件，值为空。
        /// </summary>
        public List<string> AttachmentFiles
        {
            get { return _AttachmentFiles; }
            set { _AttachmentFiles = value; }
        }
       


        #region ISysMsg 成员

        string _mailSubject = string.Empty;
        public string MsgSubject
        {
            get
            {
                return _mailSubject;
            }
            set
            {
                _mailSubject = value;
            }
        }

        string _mailContent = string.Empty;
        public string MsgContent
        {
            get
            {
                return _mailContent;
            }
            set
            {
                _mailContent = value;
            }
        }

        public string MsgType
        {
            get;
            set;
        }

        #endregion
    }
}
